package j04hashmap;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class J1map {
    public static void main(String[] args) {
        HashMap<String,Integer> map1 = new HashMap<>();
        map1.put("age",4);
        map1.put("price",15);
        System.out.println("map1 = " + map1);

        HashMap<String,Integer> map2 = new HashMap<>();
        map2.putAll(map1);
        map2.put("blood",1000);
        map2.put("blood",1001);
        map2.replace("blood",300);
        map2.replace("blood1",10);//失败

        System.out.println("map2 = " + map2);
        System.out.println(map2.get("blood"));//300
        System.out.println(map2.get("blood7"));//?
    }
}

class J2{
    public static void main(String[] args) {
        Map<String,String> m1 = new HashMap<>();
        m1.put("name","阿凡达");//avatar
        m1.put("type","科幻");
        Set<String> s1 = m1.keySet();
        System.out.println("s1 = " + s1);
        Collection<String> c1 = m1.values();
        System.out.println("c1 = " + c1);
        System.out.println("====");
        Set<Map.Entry<String,String>> sEntry = m1.entrySet();
        System.out.println("sEntry = " + sEntry);
        System.out.println("=-==");
        System.out.println(m1.containsKey("type"));//true
        System.out.println(m1.size());//2
    }
}
